<template>
   <van-row v-if="user">
     <van-col :span="24">
       <img
         style="width:100px;height:100px"
         :src="user.userImg"
       />
       <div>用户名：{{user.username}}</div>
     </van-col>
   </van-row>
   <van-row v-else>
     <van-col :span="24">
       <van-button type="primary" @click="toLogin">去登录</van-button>
     </van-col>
   </van-row>
 </template>
 
 <script setup>
 import { onMounted, ref , getCurrentInstance } from "vue";
 
 const user = ref(null);
 
 const {proxy} = getCurrentInstance();
 
 const toLogin = ()=>{
   proxy.$router.push('/login');
 }
 
 onMounted(()=>{
   let userJson = window.localStorage.getItem("loginUser");
   if(userJson){
     user.value =JSON.parse(userJson);
   }
 })
 </script>
 
 <style>
 </style>